/**
 * <p>Title: OptionsDao.java</p>
 * <p>Description: DoNotes</p>
 * @author WangJun
 * @date 2009/11/25 14:15:32
 * @version 1.0
 */
package net.donotes.blog.dao;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import net.donotes.blog.pojo.Options;
import net.donotes.util.dao.PMF;

/**
 * @author WangJun
 *
 */
public class OptionsDao {
	/**
	 * Title: addOptions
	 * @param options
	 */
	public void addOptions(Options options) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(options);
        } finally {
          //  pm.close();
        }
	}
	
	/**
	 * Title: delOptions
	 * @param options
	 */
	public void delOptions(Options options) {
		
	}
	
	/**
	 * Title: getOptions
	 * @param id
	 * @return
	 */
	public String getOptions(String id) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Options.class);
	    query.setFilter("id == idParam");
		query.declareParameters("String idParam");

		List<Options> resultes = (List<Options>)query.execute(id);
		if (resultes.iterator().hasNext()) {
			return resultes.get(0).getValue();
		} else {
			return "0";
			// return null;
		}
	}
	
	/**
	 * Title: listOptions
	 * @param options
	 * @return
	 */
	public List<Options> listOptions(Options options) {
		return null;
	}
	
	/**
	 * Title: updOptions
	 * @param options
	 */
	public void updOptions(Options options) {
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    try {
	    	Options o = pm.getObjectById(Options.class, options.getId());
	    	o.setValue(options.getValue());
	    } finally {
	        pm.close();
	    }
	}
}
